void main()
{
	vec3 normal, lightDir;
	vec4 diffuse, ambient, globalAmbient;
	float NdotL;

	normal = normalize(gl_NormalMatrix * gl_Normal);

	if (normal.z < 0)
		normal.z = -normal.z;

	lightDir = normalize(vec3(gl_LightSource[0].position));
	NdotL = max(dot(normal, lightDir), 0.0);
	diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
	ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
	globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;

	if (gl_Color.r == 0 && gl_Color.g == 0 && gl_Color.b == 0)
	{
		gl_FrontColor =  NdotL * diffuse + globalAmbient + ambient;
	}
	else
	{
		gl_FrontColor = NdotL * gl_Color;
	}
	
	gl_FrontColor.a = gl_Color.a;

	gl_BackColor = gl_FrontColor;

	gl_TexCoord[0] = gl_MultiTexCoord0;

	gl_Position = ftransform();
}